#include "stm8s.h"
#include "qumi_config.h"

bool g_power = TRUE;

/*void noWater(void)*/
/*{*/
  /*//Close Atomizer*/
  /*Atomizer_Set(0);*/

  /*//Blink Water Red LED to notify User there is no water left.*/
  /*LED_State(LED_INDEX_WATER, LED_RED_BLINK);*/
/*}*/

void Delay100US(void)
{
  uint16_t us = 256;
  while (us != 0)
  {
    --us;
  }
}

void Delay10US(void)
{
  uint8_t us = 23;
  while (us != 0)
  {
    --us;
  }
}

void DelayUS(uint16_t us)
{
  if (us >= 100)
  {
    while (us / 100)
    {
      Delay100US();
      us -= 100;
    }
  }
  if (us >= 10)
  {
    while ( us / 10 )
    {
      Delay10US();
      us -= 10;
    }
  }

  while (us != 0)
  {
    --us;
  }
}

void DelayMS(uint16_t ms)
{
  uint32_t delay = ms * 2000;

  while (delay != 0)
  {
    delay--;
  }
}

/*void ResetWiFi(void)*/
/*{*/
  /*GPIO_WriteLow(WIFI_RST_PORT, WIFI_RST_PIN);*/
  /*IWDG_ReloadCounter();  */
  /*DelayMS(500);*/
  /*IWDG_ReloadCounter();  */
  /*GPIO_WriteHigh(WIFI_RST_PORT, WIFI_RST_PIN);*/
/*}*/

/*void ChangePower(bool newState)*/
/*{*/
  /*if (newState != g_power)*/
  /*{*/
    /*if (newState)*/
    /*{*/
      /*//from power off to power on*/
      /*TIM1_Cmd(ENABLE);*/
      /*[>TIM2_Cmd(ENABLE);<]*/
      /*//TODO: enable outer sensor*/
    /*}*/
    /*else*/
    /*{*/
      /*//from power on to power off*/
      /*TIM1_Cmd(DISABLE);*/
      /*[>TIM2_Cmd(DISABLE);<]*/
      /*//TODO: disable outer sensor*/
      
    /*}*/
    /*g_power = newState;*/
  /*}*/
/*}*/
